﻿using UnityEngine;

/// <summary>
/// 通用单例模板
/// </summary>
namespace SLG_Demo_0
{
	public class Singleton<T> where T : new()
	{
		private static T m_Instance;

		public static T Instance
		{
			get
			{
				if (m_Instance == null)
				{
					m_Instance = new T();
				}

				return m_Instance;
			}
		}
	}

	/// <summary>
	/// 需要继承 MonoBehaviour 的单例
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class MonoBehaviour_Singleton<T> : MonoBehaviour where T : new()
	{
		private static T m_Instance;

		public static T Instance
		{
			get
			{
				if (m_Instance == null)
				{
					m_Instance = new T();
				}

				return m_Instance;
			}
		}
	}
}
